/*
 * @lc app=leetcode.cn id=1974 lang=typescript
 *
 * [1974] 使用特殊打字机键入单词的最少时间
 */

// @lc code=start
function minTimeToType(word: string): number {
    let now = 0;
    let step = 0;
    for (let i = 0; i < word.length; i++) {
        const code = word.charCodeAt(i) - 97;
        const ThisStep = Math.abs(code - now);
        if (ThisStep < 13) {
            step += ThisStep;
        } else {
            step += 26 - ThisStep;
        }
        now = code;
        step++;
    }
    return step;
}
// @lc code=end
